package com.turing.post.cardmanagement.util;

import java.io.Serializable;

@SuppressWarnings("serial")
public class CardApdu implements Serializable {
	/**
	 * 缺省的KEY(8)
	 */
	public final static String DEFAULT_KEY_8 = "0000000000000000";

	/**
	 * 缺省的KEY(16)
	 */
	public final static String DEFAULT_KEY_16 = "00000000000000000000000000000000";

	/**
	 * 成功返回码
	 */
	public final static String APDU_RESPCODE_SUCC = "9000";

	/**
	 * 文件未找到
	 */
	public final static String APDU_RESPCODE_FILE_NOTFOUND = "6A82";

	/**
	 * 记录未找到
	 */
	public final static String APDU_NO_REC_FOUND = "6A83";

	/**
	 * 执行出错时停止
	 */
	public final static int APDU_ERR_STOP = 0x80;

	/**
	 * 执行出错时忽略
	 */
	public final static int APDU_ERR_IGNORE = 0x00;

	/**
	 * 密钥MAC线路保护
	 */
	public final static int KEY_MAC_BIT = 0x80;

	/**
	 * 密钥DES线路保护
	 */
	public final static int KEY_DES_BIT = 0x40;

	/**
	 * TAC密钥
	 */
	public final static int KEY_DTK = 0x25;

	/**
	 * 圈存密钥
	 */
	public final static int KEY_DLK = 0x26;

	/**
	 * 消费密钥
	 */
	public final static int KEY_DPK = 0x27;

	/**
	 * 圈提密钥
	 */
	public final static int KEY_DULK = 0x28;

	/**
	 * 更新透支限额密钥
	 */
	public final static int KEY_DUK = 0x29;

	/**
	 * PIN密钥
	 */
	public final static int KEY_PIN = 0x3A;

	/**
	 * PIN解锁密钥
	 */
	public final static int KEY_DPUK = 0x37;
	
	/**
	 * 重装PIN密钥
	 */
	public final static int KEY_DRPK = 0x38;

	/**
	 * 应用维护密钥(卡片维护密钥)
	 */
	public final static int KEY_DAMK = 0x36;

	/**
	 * 外部认证密钥(卡片主控密钥/应用主控密钥)
	 */
	public final static int KEY_DEAK = 0x39;

	/**
	 * 内部认证密钥
	 */
	public final static int KEY_DACK = 0x30;

	/**
	 * 打开设备寻卡
	 */
	public final static int APDU_OPEN = 0x01;

	/**
	 * 取随机数4字节
	 */
	public final static int APDU_GET_CHALLENGE_MAC = 0x02;

	/**
	 * 取随机数(8字节)
	 */
	public final static int APDU_GET_CHALLENGE = 0x32;

	/**
	 * 外部认证
	 */
	public final static int APDU_EXTERNAL_AUTHENTICATION = 0x03;

	/**
	 * 创建文件
	 */
	public final static int APDU_CREATE_FILE = 0x04;

	/**
	 * 选择文件
	 */
	public final static int APDU_SELECT_FILE = 0x05;

	/**
	 * 设置KEY
	 */
	public final static int APDU_WRITE_KEY = 0x06;

	/**
	 * 读BINARY文件
	 */
	public final static int APDU_READ_BINARY = 0x07;

	/**
	 * 写BINARY文件
	 */
	public final static int APDU_WRITE_BINARY = 0x08;

	/**
	 * 取电子钱包或电子存折余额
	 */
	public final static int APDU_GET_BALANCE = 0x09;

	/**
	 * 取交易明细
	 */
	public final static int APDU_GET_EPLIST = 0x0A;

	/**
	 * 圈存初始化
	 */
	public final static int APDU_LOAD_INIT = 0x0B;

	/**
	 * 圈存
	 */
	public final static int APDU_LOAD = 0x0C;

	/**
	 * 关闭设备
	 */
	public final static int APDU_CLOSE = 0x7F;

	/**
	 * APDU指令类型
	 */
	private int apduCategory;

	/**
	 * APDU指令
	 */
	private String apdu;

	/**
	 * APDU指令执行结果
	 */
	private String apduResult;

	public void setApduCategory(int apduCategory) {
		this.apduCategory = apduCategory;
	}

	public int getApduCategory() {
		return this.apduCategory;
	}

	public int getApduInstruction() {
		return this.apduCategory & (~APDU_ERR_STOP);
	}

	public boolean isIgnore() {
		return ((this.apduCategory & (~APDU_ERR_STOP)) == this.apduCategory);
	}

	public void setApdu(String apdu) {
		this.apdu = apdu;
	}

	public String getApdu() {
		return apdu;
	}

	public void setApduResult(String apduResult) {
		this.apduResult = apduResult;
	}

	public String getApduResult() {
		return apduResult;
	}
}
